package com.quad.innovators.salesease.converter;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quad.innovators.salesease.common.result.PageResultBean;
import com.quad.innovators.salesease.model.common.Option;
import com.quad.innovators.salesease.model.entity.SysRole;
import com.quad.innovators.salesease.model.form.SysRoleForm;
import com.quad.innovators.salesease.model.vo.SysRolePageVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

/**
 * 角色对象转换器
 *
 * @author haoxr
 * @since 2022/5/29
 */
@Mapper(componentModel = "spring")
public interface SysRoleConverter {

    @Mappings({
            @Mapping(target = "items", source = "records"),
            @Mapping(target = "pageInfo.currPage", source = "current"),
            @Mapping(target = "pageInfo.totalCount", source = "total"),
            @Mapping(target = "pageInfo.pageSize", source = "size")
    })
    PageResultBean<SysRolePageVO> toPageVo(Page<SysRole> page);

    @Mappings({
            @Mapping(target = "value", source = "code"),
            @Mapping(target = "label", source = "name")
    })
    Option<String> entity2Option(SysRole role);

    @Mappings({
            @Mapping(target = "value", source = "code"),
            @Mapping(target = "label", source = "name")
    })
    List<Option<String>> entities2Options(List<SysRole> roles);

    @Mappings({
            @Mapping(target = "status", expression = "java(com.quad.innovators.salesease.enums.IBaseEnum.getEnumByValue(roleForm.getStatus(), com.quad.innovators.salesease.enums.StatusEnum.class))")
    })
    SysRole toEntity(SysRoleForm roleForm);

    @Mappings({
            @Mapping(target = "status", expression = "java(entity.getStatus().getValue())")
    })
    SysRoleForm toForm(SysRole entity);
}